<template>
  <!--文件对象存储配置-->
  <div class="search">
    <f-form ref="form" form-key="oss">
      <f-form-item label="服务提供商" name="serviceName":required="true" type="select" :data="api.common.ossType" :value.sync="OSS_USED" width="400px"/>
      <f-form-item label="accessKey" name="accessKey" :required="true" :value="ALI_OSS.accessKey" v-if="OSS_USED=='ALI_OSS'" width="400px"/>
      <f-form-item label="secretKey" name="secretKey" :required="true" :value="ALI_OSS.secretKey" v-if="OSS_USED=='ALI_OSS'" width="400px"/>
      <f-form-item label="bucket空间" name="bucket" :value="ALI_OSS.bucket" v-if="OSS_USED=='ALI_OSS'" width="400px"/>
      <f-form-item label="endpoint域名" name="endpoint" :value="ALI_OSS.endpoint" :slotObj="linkSolt" v-if="OSS_USED=='ALI_OSS'" width="400px"/>
      <f-form-item label="存储路径" name="filePath" :required="true" :value="LOCAL_OSS.filePath" v-if="OSS_USED=='LOCAL_OSS'" width="400px"/>
      <f-form-item label="文件预览地址" name="endpoint2" :required="true" :value="LOCAL_OSS.endpoint" :slotObj="linkSolt" v-if="OSS_USED=='LOCAL_OSS'" width="400px"/>
    </f-form>
  </div>
</template>

<script>
  export default {
    name: 'ossForm',
    props: {},
    data () {
      return {
        isAdd: true,
        OSS_USED: 'LOCAL_OSS',
        LOCAL_OSS: {},
        ALI_OSS: {
          http:'http://'
        }
      }
    },
    methods: {
      getOss () {
        this.http.get(this, {
          url: this.api.config.oss,
          data: {},
          success: function (me, data) {
            if (data.ALI_OSS) {
              me.ALI_OSS = JSON.parse(data.ALI_OSS)
              console.info("#######", me.ALI_OSS)
            }
            if (data.LOCAL_OSS) {
              me.LOCAL_OSS = JSON.parse(data.LOCAL_OSS)
            }
            me.OSS_USED = data.OSS_USED
          }
        })
      },
      setData () {
        this.$refs.form.resetFields()
        this.getOss()
      },
      handleSubmit () {
        this.$refs.form.getForm().validateFields((valid, values) => {
            if (!valid) {
              this.http.post(this, {
                url: this.api.config.ossSave,
                data: {
                  params: values
                },
                success: function (me) {

                }
              })
            }
          }
        )
      }
    },
    computed: {
      linkSolt: function () {
        return {
          name: 'http',
          slotName: 'addonBefore',
          value: this.ALI_OSS.http,
          width: 90,
          data: [{ label: 'http://', value: 'http://' }, { label: 'https://', value: 'https://' }]
        }
      }
    },
    created () {
      this.getOss()
    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
